﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace QuanLyCongDoanVien.UserControls
{
    public partial class ucCapNhatToCongDoan : UserControl
    {
        public ucCapNhatToCongDoan()
        {
            InitializeComponent();
        }

        private void ucCapNhatToCongDoan_Load(object sender, EventArgs e)
        {
            try
            {
                cboToCongDoan.DataSource = ToCongDoanBUS.LayDanhSach();
                cboToCongDoan.DisplayMember = "TenToCongDoan";
                cboToCongDoan.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        

        private void btnThoat_Click(object sender, EventArgs e)
        {
            txtTenToCapNhat.Text = "";
            cboToCongDoan.SelectedIndex = -1;
        }

        private void btnDongY_Click(object sender, EventArgs e)
        {
            if (txtTenToCapNhat.Text == "")
            {
                MessageBox.Show("Vui lòng nhập tên tổ công đoàn");
                return;
            }
            string strTenCu = ((ToCongDoanDTO)cboToCongDoan.SelectedItem).TenToCongDoan;
            string strTenMoi = txtTenToCapNhat.Text.Trim();
            try
            {
                int iResult = ToCongDoanBUS.Sua(strTenCu, strTenMoi);
                if (iResult == 1)
                {
                    MessageBox.Show("Đã sửa tên tổ công đoàn");
                    txtTenToCapNhat.Text = "";
                    cboToCongDoan.DataSource = ToCongDoanBUS.LayDanhSach();
                    cboToCongDoan.DisplayMember = "TenToCongDoan";
                    cboToCongDoan.SelectedIndex = -1;
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
